


$(function() {

    // Expand admin header images
    $('#headerimageslink').click(function() {
        $("#headerimages").slideToggle("slow");
        return false;
    });
    
    
    
    // Dialog Link
    $('#dialog_link').click(function() {
        $('#dialog').dialog('open');
        return false;
    });

    // Used when dialog dont show properly
    $("#dialog").parent().appendTo("/html/body/form[0]/");


    //Sidebar Accordion Menu:
    $("#mainnav li ul").hide(); // Hide all sub menus
    $("#mainnav li a.current").parent().find("ul").slideToggle("slow"); // Slide down

    $("#mainnav li a.nav-top-item").click( // When a top menu item is clicked...
			function() {
			    $(this).parent().siblings().find("ul").slideUp("normal"); // Slide back
			    $(this).next().slideToggle("normal"); // Slide down submenu
			    return false; //Need to be set to false
			}
	);

    $("#mainnav li a.no-submenu").click( // When a menu item with no sub menu is clicked...
			function() {
			    window.location.href = (this.href); // Just open the link instead of a sub menu
			    return true;
			}
		);


    // Alignement
    $("#mainnav li .nav-top-item").hover(
			function() {
			    $(this).stop().animate({ paddingRight: "25px" }, 200);
			},
			function() {
			    $(this).stop().animate({ paddingRight: "15px" });
			}
		);

    $('.content-box .content-box-content div.tab-content').hide(); // Hide the content divs
    $('ul.content-box-tabs li a.default-tab').addClass('current'); // Add the class "current" to the default tab
    $('.content-box-content div.default-tab').show(); // Show the div with class "default-tab"

    $('.content-box ul.content-box-tabs li a').click( // When a tab is clicked...
			function() {
			    $(this).parent().siblings().find("a").removeClass('current'); // Remove "current" class from all tabs
			    $(this).addClass('current'); // Add class "current" to clicked tab
			    var currentTab = $(this).attr('href'); // Set variable "currentTab" to the value of href of clicked tab
			    $(currentTab).siblings().hide(); // Hide all content divs
			    $(currentTab).show(); // Show the content div with the id equal to the id of clicked tab

			}
		);

    $('.content-box ul.content-box-tabs li a').click( // tab
			function() {
			    $(this).parent().siblings().find("a").removeClass('current'); // Remove "current" class from all tabs
			    $(this).addClass('current'); // Add class "current" to clicked tab
			    var currentTab = $(this).attr('href'); // Set variable "currentTab" to the value of href of clicked tab
			    $(currentTab).siblings().hide(); // Hide all content divs
			    $(currentTab).show(); // Show the content div with the id equal to the id of clicked tab

			}
	);

    $('.content-box ul.content-box-tabs li a.no-js-tab').click( // When a tab with the class "no-js-tab" is clicked...
			function() {

			    //window.location.href = (this.href); // Just open the link instead of showing the tab's content
			    return true;
			}
		);


    //Close button:
    $(".close").click(
			function() {
			    $(this).parent().fadeTo(400, 0, function() { // Links with the class "close" will close parent
			        $(this).slideUp(400);
			    });
			    return false;
			}
		);

    // Alternating table rows:
    $('.admTable tr:even').addClass("alt-row"); // Add class "alt-row" to even table rows
    //$('.noover tr').removeClass("alt-row"); // Add class "alt-row" to even table rows

    // Check all checkboxes when the one in a table head is checked:

    $('.check-all').click(
			function() {
			    $(this).parent().parent().parent().parent().find("input[type='checkbox']").attr('checked', $(this).is(':checked'));
			}
	);



        //Header images ToolTip hover
		xOffset = 10;
		yOffset = 30;

		$("div.screenshot").hover(function(e) {
		    this.t = this.title;
		    this.title = "";
		    var c = (this.t != "") ? "<br/>" + this.t : "";
		    $("body").append("<p id='screenshot'><img src='" + this.rel + "' alt='Preview' />" + c + "</p>");
		    $("#screenshot")
		.css("top", (e.pageY - xOffset) + "px")
		.css("left", (e.pageX + yOffset) + "px")
		.fadeIn("fast");
		},
        function() {
            this.title = this.t;
            $("#screenshot").remove();
        });
		$("div.screenshot").mousemove(function(e) {
		    $("#screenshot")
		.css("top", (e.pageY - xOffset) + "px")
		.css("left", (e.pageX + yOffset) + "px");
		});



		$(function() {
		$("li.clickimage").click(function() {
		        $("div.switch", this).toggle();
		    });
		});

});